/** Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 * */
function jqVersion(){
	alert($().jquery);
}
// JQUERY POP UPS
jQuery(function($) {
	var currentId="";
	
	$(document).on("click", "a.topopup", function() {
			//loading(); // loading
			//setTimeout(function(){ // then show popup, deley in .5 second
			//	loadPopup(); // function show popup
			//}, 500); // .5 second
		currentId = $(this).attr('id');	
		loadPopup();
	return false;
	});
	/*$("a.topopup").click(function() {
			//loading(); // loading
			//setTimeout(function(){ // then show popup, deley in .5 second
			//	loadPopup(); // function show popup
			//}, 500); // .5 second
		loadPopup();
	return false;
	});*/
	
	$(document).on("hover", "div.close", function() {
						$('span.ecs_tooltip').show();
					},
					function () {
    					$('span.ecs_tooltip').hide();
  					}
				);

	/* event for close the popup */
	/*$("div.close").hover(
					function() {
						$('span.ecs_tooltip').show();
					},
					function () {
    					$('span.ecs_tooltip').hide();
  					}
				);*/

	$(document).on("click", "div.close", function() {
		disablePopup();  // function close pop up
	});
	/*$("div.close").click(function() {
		disablePopup();  // function close pop up
	});*/

	$(this).keyup(function(event) {
		if (event.which == 27) { // 27 is 'Esc' in the keyboard
			disablePopup();  // function close pop up
		}
	});
	$(document).on("click", "div#backgroundPopup", function() {
		disablePopup();  // function close pop up
	});
    
    /*$("div#backgroundPopup").click(function() {
		disablePopup();  // function close pop up
	});*/
	$(document).on("click", "a.livebox", function() {
		alert('Hello World!');
	return false;
	});
	
	/*$('a.livebox').click(function() {
		alert('Hello World!');
	return false;
	});*/

	 /************** start: functions. **************/
	function loading() {
		$("div.loader").show();
	}
	function closeloading() {
		$("div.loader").fadeOut('normal');
	}

	var popupStatus = 0; // set value

	function loadPopup() {
		if(popupStatus == 0) { // if value is 0, show popup
			//closeloading(); // fadeout loading
			$("div[id='" + currentId + "']").fadeIn(0500); // fadein popup div
			//$("#backgroundPopup").css("opacity", "0.7"); // css opacity, supports IE7, IE8
			//$("#backgroundPopup").fadeIn(0001);
			popupStatus = 1; // and set value to 1
		}
	}

	function disablePopup() {
		if(popupStatus == 1) { // if value is 1, close popup
			$("div[id='" + currentId + "']").fadeOut("normal");
			//$("#backgroundPopup").fadeOut("normal");
			popupStatus = 0;  // and set value to 0
		}
	}
	/************** end: functions. **************/
}); // jQuery End